package com.koron.css2.clientCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.bean.UserReuseBean;
import com.koron.css2.clientCenter.mapper.ReuseUserMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 用户复用删除
 * 
 * @author 甄玉晴
 *
 */
public class ReuseUserDelete implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			ReuseUserMapper mapper = factory.getMapper(ReuseUserMapper.class);
			UserReuseBean bean = JsonUtils.objectToPojo(req.getData(), UserReuseBean.class);
			// 获取单据当前状态
			bean = mapper.getUserReuseInfoById(bean.getId());
			if (bean == null) {
				return MessageBean.create(Constant.ILLEGAL_PARAMETER, "该复用信息不存在", void.class);
			}
			if (bean.getProcessState() != null && !bean.getProcessState().equals("")) {
				return MessageBean.create(Constant.ILLEGAL_PARAMETER, "状态不是草稿，该复用信息不能删除", void.class);
			}
			// 删除
			mapper.userReuseDelete(bean.getId());
			return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", void.class);
		} catch (Exception e) {
			logger.error("复用信息删除失败", e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "复用信息删除失败", void.class);
		}
	}

}
